/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-07 11:22:02
 * @LastEditTime: 2022-06-28 20:34:38
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/model/system"
	"github.com/maxyang107/jinglan/service/admin"
)

/**
 * @description: 方法描述：设置系统参数
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func AddOrUpdateConfig(c *gin.Context) {
	var param_ system.SysConfig

	if err := c.ShouldBind(&param_); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	err := admin.AdminConfigService.AddOrUpdateConfig(param_)

	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "设置成功", c)
}

/**
 * @description: 方法描述：获取系统配置
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetSysConfigList(c *gin.Context) {
	cl := admin.AdminConfigService.GetSysConfigList()
	common.ResponseDetailToJson(http.StatusOK, cl, "success", c)
}

/**
 * @description: 方法描述：获取系统配置详细信息
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetDetail(c *gin.Context) {
	sc := system.GetSysConfigDetail(common.REGISTERAIRDROP)
	m := make(map[string]interface{})
	json.Unmarshal([]byte(sc.ConfigValue), &m)

	common.ResponseDetailToJson(http.StatusOK, m, "success", c)

}
